//
//  ExihibitionPageItemViewController.m
//  HAODE
//
//  Created by LiYinDi on 16/4/11.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "ExhibitionPageItemViewController.h"
#import <JavaScriptCore/JavaScriptCore.h>
#import "ExhibitionObject.h"
#import "ProductDetailViewController.h"
@interface ExhibitionPageItemViewController ()<TestDelegate>

@end

@implementation ExhibitionPageItemViewController
-(void)viewWillAppear:(BOOL)animated
{
    
    [self setNavigation];
    [self setAutolayout];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [_webView setPaginationMode:UIWebPaginationModeTopToBottom];
    [_webView setBackgroundColor:[UIColor clearColor]];
    NSURL *url = [[NSURL alloc]initWithString:_url];
    //    NSLog(@"_url=====%@",_url);
    [_webView loadRequest:[NSURLRequest requestWithURL:url]];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    
    
//    [self performSelector:@selector(getAchieveWebViewHeight) withObject:nil afterDelay:0.3];
    JSContext *context=[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    
    //js调用iOS
    //第一种情况
    //其中test1就是js的方法名称，赋给是一个block 里面是iOS代码
    
    ExhibitionObject *exhiObject=[ExhibitionObject  new];
    exhiObject.delegate=self;
    context[@"appJs"]=exhiObject;
    
    //
    //    NSString *jsStr2=@"appJs.gotoItemDetail('参数1')";
    //    [context evaluateScript:jsStr2];
}
-(void)productDetail:(NSString *)itemID
{
    ProductDetailViewController *detailViewController = [[ProductDetailViewController alloc] init];
//    detailViewController.itemIdStr=itemID;
//    
//   detailViewController.saveTypeStr=@"";
//    
//    detailViewController.typeString=@"Exhibition";
    //下面继续盘点的带出来的数据
    
  [self.navigationController pushViewController:detailViewController animated:YES];

}
-(void)getAchieveWebViewHeight
{
    NSString *meta = [NSString stringWithFormat:@"document.getElementsByName(\"viewport\")[0].content = \"width=%f, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"", _webView.frame.size.width];
    [_webView stringByEvaluatingJavaScriptFromString:meta];
}


-(void)setNavigation
{
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
 
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    UILabel *titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0,100, 21)];
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.text=@"组合详情";
    
    self.navigationItem.titleView = titleLabel;
    self.navigationController.navigationBar.barStyle =UIBaselineAdjustmentNone ;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    
}

-(void)BackAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)setAutolayout
{
    [_webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top);
        
    }];
}


@end
